package com.xiaocg.juc.lock;

import java.util.concurrent.TimeUnit;

public class DeadLockDemo {
    public static void main(String[] args) {
        final Object objectA = new Object();
        final Object objectB = new Object();

        new Thread(()->{
            synchronized (objectA){
                System.out.println("获取a锁。。。。。。。。。。。");
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {

                }
                synchronized (objectB){
                    System.out.println("获取b锁");
                }
            }
        },"t1").start();

        new Thread(()->{
            synchronized (objectB){
                System.out.println("获取b锁-----------");
                synchronized (objectA){
                    System.out.println("获取a锁");
                }
            }
        },"t2").start();

    }
}
